package leetcode;

public class ques_14 {
    public static String longestCommonPrefix(String[] strs) {
        //if(strs.length==1)return "";
        String str=strs[0];
        for (String index:strs) {
            while(!index.startsWith(str)){
                str=str.substring(0,str.length()-1);
            }
        }
        return str;
    }


    public static void main(String[] args) {
       String[]strs ={"flower","flow","flight"};
        String[]strs1 ={"ab","a"};
        System.out.println(longestCommonPrefix(strs));
        System.out.println(longestCommonPrefix(strs1));

    }
}
